from openpyxl import Workbook#创建新文档需要调用Workbook
from openpyxl import load_workbook
wb = Workbook()
wb.create_sheet("first")#创建新工作表并命名为“first”
wb.create_sheet("second")#创建新工作表并命名为“second”
wb.save("try.xlsx")#保存新建xlsx文件
wb = load_workbook(r"try.xlsx")
ws = wb.get_sheet_by_name("first")
ws['A1'] = "数学"
ws['B1'] = "语文"
ws.cell(2,1,90)
ws.cell(2,2,91)
ws.append([80,81])
ws['c2'] = "=sum(A2:B2)"
ws['c3'] = "=sum(A3:A3)"
wb.save(r"try.xlsx")
#运行成功了 但不知道为什么显示错误